package com.woniu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.Vacate;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
public interface VacateMapper extends BaseMapper<Vacate> {
    @Update("<script>                                           "
            + "UPDATE vacate                                   "
            + "<set>                                            "
            + "  <if test='vaConfReason!= null'> va_conf_reason=#{vaConfReason}, </if> "
            + "  <if test='vaConfTime != null'> va_conf_time=#{vaConfTime}, </if> "
            + "  <if test='vaStatus != null'> va_status=#{vaStatus}, </if> "
            + "  <if test='confUserId != null'> conf_user_id=#{confUserId}, </if> "
            + "  <if test='vaEndTime != null'> va_end_time=#{vaEndTime} </if> "
            + "</set>                                           "
            + "WHERE va_id = #{vaId}                                 "
            + "</script>                                        ")
    void update(Vacate vacate);

    @Select("SELECT vacate.*,u1.user_name,d1.dept_name,u2.user_name,d2.dept_name " +
            "FROM vacate,user AS u1,user AS u2,dept AS d1,dept AS d2" +
            " ${ew.customSqlSegment} " +
            "AND u1.dept_id=d1.dept_id " +
            "AND u2.dept_id=d2.dept_id")
    @Results(id = "VacateMap", value = {
            @Result(column = "d1.dept_name", property = "dept.deptName"),
            @Result(column = "d2.dept_name", property = "confUserDept.deptName"),
            @Result(column = "u1.user_name", property = "user.userName"),
            @Result(column = "u2.user_name", property = "confUser.userName")
    })
    Page<Vacate> getVacateWithPage(Page<Vacate> page, @Param(Constants.WRAPPER) Wrapper<Vacate> wrapper);
}
